<?php if (!isset($_SESSION)) session_start(); ?>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="../../docs-assets/ico/favicon.png">

<title>Koreanet</title>

<!-- Nanum Webfont -->
<style>
* {
	font-family: 'NanumGothic' !important;
}
</style>
<script src="http://www.google.com/jsapi"></script>
<script>
 google.load( "webfont", "1" );
 google.setOnLoadCallback(function() {
  WebFont.load({ custom: {
   families: [ "NanumGothic" ],
   urls: [ "http://fontface.kr/NanumGothic/css" ]
  }});
 });
</script>

<!-- Bootstrap core CSS -->
<link href="./dist/css/bootstrap.css" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="./css/templete.css" rel="stylesheet">

</head>

<body>
<?php include 'header.php';?>

	<div class="container container_bottom">
		<div class="row">
			<div class="col-md-12">
<?php
/**
 * PHPExcel
 *
 * Copyright (C) 2006 - 2014 PHPExcel
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * @category PHPExcel
 * @package PHPExcel
 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt	LGPL
 * @version 1.8.0, 2014-03-02
 */

/**
 * 현재 디렉토리의 엑셀 파일을 지운다.
 */

$path = "./"; // 오픈하고자 하는 폴더
$dirs = dir ( $path ); // 오픈하기
while ( false !== ($entry = $dirs->read ()) ) { // 읽기
	if (strpos ( $entry, 'xls' ) !== false) {
		unlink ( $entry );
		echo date ( 'H:i:s' ), ' 기존에 생성된 파일을 삭제합니다. : ' . $entry . '<br/>';
	}
}
$dirs->close (); // 닫기

/**
 * Error reporting
 */
error_reporting ( E_ALL );
ini_set ( 'display_errors', TRUE );
ini_set ( 'display_startup_errors', TRUE );

define ( 'EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />' );

date_default_timezone_set ( 'Europe/London' );

/**
 * Include PHPExcel
 */
require_once dirname ( __FILE__ ) . '/Classes/PHPExcel.php';

/*
 * After doing some test, I've got these results benchmarked for writing to Excel2007: Number of rows	Seconds to generate 200				3 500				4 1000			6 2000			12 4000			36 8000			64 15000			465
 */

// Create new PHPExcel object
$type = $_GET ['type'];
$sDate = $_GET ['sDate'];
$eDate = $_GET ['eDate'];

$rText = '';
switch ($type){
	case 1:
		$rText = " 인력 데이터를 엑셀 파일로 만들 중비합니다.";
		break;
	case 2:
		$rText = " 차량 데이터를 엑셀 파일로 만들 중비합니다.";
		break;
	case 3:
		$rText = " 일일 결산 데이터(".$sDate."~".$eDate.")를 엑셀 파일로 만들 중비합니다.";
		break;
	case 4:
		$rText = " 월 결산 데이터(".$sDate."~".$eDate.")를 엑셀 파일로 만들 중비합니다.";
		break;
}
echo date ( 'H:i:s' ), $rText, EOL;
$objPHPExcel = new PHPExcel ();

// Set document properties
echo date ( 'H:i:s' ), " 엑셀 파일을 설정합니다.", EOL;
$objPHPExcel->getProperties ()->setCreator ( "Koreanet" )->setTitle ( "Office 2007 XLSX Document" )->setSubject ( "Office 2007 XLSX Document" )->setDescription ( "Document for Office 2007 XLSX, generated using PHP classes." )->setKeywords ( "Office 2007 openxml php" )->setCategory ( "result file" );

// Create a first sheet
echo date ( 'H:i:s' ), " 엑셀 파일에 인덱스 데이터를 추가합니다.", EOL;
$objPHPExcel->setActiveSheetIndex ( 0 );
$i = 1;
switch ($type) {
	case 1 :
		$objPHPExcel->getActiveSheet ()->setCellValue ( 'A' . $i, "사번" )->setCellValue ( 'B' . $i, "비번" )->setCellValue ( 'C' . $i, "성명" )->setCellValue ( 'D' . $i, "주민번호" )->setCellValue ( 'E' . $i, "면허번호" )->setCellValue ( 'F' . $i, "화물종사자자격번호" )->setCellValue ( 'G' . $i, "사업자등록번호" )->setCellValue ( 'H' . $i, "사업자개업일" )->setCellValue ( 'I' . $i, "입사보고" )->setCellValue ( 'J' . $i, "회원등급" )->setCellValue ( 'K' . $i, "입사일" )->setCellValue ( 'L' . $i, "퇴사일" )->setCellValue ( 'M' . $i, "직책" )->setCellValue ( 'N' . $i, "급여일" )->setCellValue ( 'O' . $i, "거래은행명" )->setCellValue ( 'P' . $i, "예금주" )->setCellValue ( 'Q' . $i, "계좌번호" )->setCellValue ( 'R' . $i, "이메일" )->setCellValue ( 'S' . $i, "주소" )->setCellValue ( 'T' . $i, "출퇴근거리" )->setCellValue ( 'U' . $i, "출퇴근시간" )->setCellValue ( 'V' . $i, "gps식별번호" )->setCellValue ( 'W' . $i, "보험료납입횟수" )->setCellValue ( 'X' . $i, "보험료" )->setCellValue ( 'Y' . $i, "거래처코드" )->setCellValue ( 'Z' . $i, "차량번호" )->setCellValue ( 'AA' . $i, "연락처" )->setCellValue ( 'AB' . $i, "기본운송료" )->setCellValue ( 'AC' . $i, "차량 할부금" )->setCellValue ( 'AD' . $i, "차량 할부 회차" )->setCellValue ( 'AE' . $i, "직영구분" )->setCellValue ( 'AF' . $i, "임시차량번호" )->setCellValue ( 'AG' . $i, "기사구분" )->setCellValue ( 'AH' . $i, "근무점포" )->setCellValue ( 'AI' . $i, "관리비" )->setCellValue ( 'AJ' . $i, "환경개선/협회비" )->setCellValue ( 'AK' . $i, "GPS 비" )->setCellValue ( 'AL' . $i, "피부양 인수" )->setCellValue ( 'AM' . $i, "시간급" )->setCellValue ( 'AN' . $i, "기본급" )->setCellValue ( 'AO' . $i, "연장수당" )->setCellValue ( 'AP' . $i, "연차수당" )->setCellValue ( 'AQ' . $i, "EARLY SLOT" )->setCellValue ( 'AR' . $i, "교통비" )->setCellValue ( 'AS' . $i, "식대비" )->setCellValue ( 'AT' . $i, "국민연금" )->setCellValue ( 'AU' . $i, "건강보험" )->setCellValue ( 'AV' . $i, "장기요양" )->setCellValue ( 'AW' . $i, "고용보험" )->setCellValue ( 'AX' . $i, "갑근세" )->setCellValue ( 'AY' . $i, "주민세" );
		break;
	case 2 :
		$objPHPExcel->getActiveSheet ()->setCellValue ( 'A' . $i, "식별번호" )->setCellValue ( 'B' . $i, "차량번호" )->setCellValue ( 'C' . $i, "차대번호" )->setCellValue ( 'D' . $i, "차량소속" )->setCellValue ( 'E' . $i, "소유구분" )->setCellValue ( 'F' . $i, "거래처코드" )->setCellValue ( 'G' . $i, "근무점포" )->setCellValue ( 'H' . $i, "번호판" )->setCellValue ( 'I' . $i, "연식(년)" )->setCellValue ( 'J' . $i, "연식(월)" )->setCellValue ( 'K' . $i, "탑 형식" )->setCellValue ( 'L' . $i, "관리비" )->setCellValue ( 'M' . $i, "환경개선비/협회비" )->setCellValue ( 'N' . $i, "GPS비용" )->setCellValue ( 'O' . $i, "현재기사" )->setCellValue ( 'P' . $i, "이전기사" )->setCellValue ( 'Q' . $i, "기사 변경 일자" )->setCellValue ( 'R' . $i, "적재량" )->setCellValue ( 'S' . $i, "적재타입" )->setCellValue ( 'T' . $i, "차종" )->setCellValue ( 'U' . $i, "형식" )->setCellValue ( 'V' . $i, "원동기형식" )->setCellValue ( 'W' . $i, "연식" )->setCellValue ( 'X' . $i, "최초등록일" )->setCellValue ( 'Y' . $i, "등록일자" )->setCellValue ( 'Z' . $i, "배기량" )->setCellValue ( 'AA' . $i, "길이" )->setCellValue ( 'AB' . $i, "너비" )->setCellValue ( 'AC' . $i, "높이" )->setCellValue ( 'AD' . $i, "최대적재량" )->setCellValue ( 'AE' . $i, "검사일" );
		break;
	case 3 :
		$objPHPExcel->getActiveSheet ()->setCellValue ( 'A' . $i, "사번" )->setCellValue ( 'B' . $i, "cusm_cd" )->setCellValue ( 'C' . $i, "brno" )->setCellValue ( 'D' . $i, "car_soyu_tp" )->setCellValue ( 'E' . $i, "출근여부" )->setCellValue ( 'F' . $i, "배송건수" )->setCellValue ( 'G' . $i, "용차업체" )->setCellValue ( 'H' . $i, "용차비용" )->setCellValue ( 'I' . $i, "기타비용1" )->setCellValue ( 'J' . $i, "기타비용2" )->setCellValue ( 'K' . $i, "휴무공제" )->setCellValue ( 'L' . $i, "note" )->setCellValue ( 'M' . $i, "입력일" );
		break;
	case 4 :
		$objPHPExcel->getActiveSheet ()->setCellValue ( 'A' . $i, "이름" )->setCellValue ( 'B' . $i, "주민번호" )->setCellValue ( 'C' . $i, "사원번호" )->setCellValue ( 'D' . $i, "차량번호" )->setCellValue ( 'E' . $i, "차량소속" )->setCellValue ( 'F' . $i, "소속지점" )->setCellValue ( 'G' . $i, "거래처코드" )->setCellValue ( 'H' . $i, "거래은행명" )->setCellValue ( 'I' . $i, "예금주" )->setCellValue ( 'J' . $i, "계좌번호" )->setCellValue ( 'K' . $i, "기사구분" )->setCellValue ( 'L' . $i, "기본운송료" )->setCellValue ( 'M' . $i, "통신비" )->setCellValue ( 'N' . $i, "세차비" )->setCellValue ( 'O' . $i, "만근지원비" )->setCellValue ( 'P' . $i, "운행장려금2" )->setCellValue ( 'Q' . $i, "용차비" )->setCellValue ( 'R' . $i, "유류비" )->setCellValue ( 'S' . $i, "휴무인센티브" )->setCellValue ( 'T' . $i, "휴무공제" )->setCellValue ( 'U' . $i, "휴무일수" )->setCellValue ( 'V' . $i, "출근일" )->setCellValue ( 'W' . $i, "운송료추가" )->setCellValue ( 'X' . $i, "도로비" )->setCellValue ( 'Y' . $i, "기타" )->setCellValue ( 'Z' . $i, "기타2(영수증)" )->setCellValue ( 'AA' . $i, "총운송료" )->setCellValue ( 'AB' . $i, "관리비" )->setCellValue ( 'AC' . $i, "부가세" )->setCellValue ( 'AD' . $i, "보험료" )->setCellValue ( 'AE' . $i, "보험료회차" )->setCellValue ( 'AF' . $i, "환경개선비_협회비" )->setCellValue ( 'AG' . $i, "자동차세" )->setCellValue ( 'AH' . $i, "GPS 비용" )->setCellValue ( 'AI' . $i, "과태료" )->setCellValue ( 'AJ' . $i, "사고접보비" )->setCellValue ( 'AK' . $i, "유류연비차액" )->setCellValue ( 'AL' . $i, "출퇴근유류비" )->setCellValue ( 'AM' . $i, "차량할부" )->setCellValue ( 'AN' . $i, "할부회차" )->setCellValue ( 'AO' . $i, "예치금" )->setCellValue ( 'AP' . $i, "선지급" )->setCellValue ( 'AQ' . $i, "기장료" )->setCellValue ( 'AR' . $i, "이체수수료" )->setCellValue ( 'AS' . $i, "도색비" )->setCellValue ( 'AT' . $i, "기타" )->setCellValue ( 'AU' . $i, "사업소득세" )->setCellValue ( 'AV' . $i, "공제합계" )->setCellValue ( 'AW' . $i, "실지급액" )->setCellValue ( 'AX' . $i, "결산일" )->setCellValue ( 'AY' . $i, "결산완료여부" )->setCellValue ( 'AZ' . $i, "실행시간" )->setCellValue ( 'BA' . $i, "비고" )->setCellValue ( 'BB' . $i, "연장수당" )->setCellValue ( 'BC' . $i, "연차수당" )->setCellValue ( 'BD' . $i, "EARLY SLOT" )->setCellValue ( 'BE' . $i, "교통비" )->setCellValue ( 'BF' . $i, "식대비" )->setCellValue ( 'BG' . $i, "국민연금" )->setCellValue ( 'BH' . $i, "건강보험" )->setCellValue ( 'BI' . $i, "장기요양" )->setCellValue ( 'BJ' . $i, "고용보험" )->setCellValue ( 'BK' . $i, "갑근세" )->setCellValue ( 'BL' . $i, "주민세" )->setCellValue ( 'BM' . $i, "디스패쳐" )->setCellValue ( 'BN' . $i, "차량보조" )->setCellValue ( 'BO' . $i, "기타수당" )->setCellValue ( 'BP' . $i, "기타경비" )->setCellValue ( 'BQ' . $i, "선급금" )->setCellValue ( 'BR' . $i, "기타공제" )->setCellValue ( 'BS' . $i, "지각/조퇴/결근공제" )->setCellValue ( 'BT' . $i, "익스_인센티브" )->setCellValue ( 'BU' . $i, "건당인센티브" )->setCellValue ( 'BV' . $i, "지급일" )->setCellValue ( 'BW' . $i, "월결공지사항" );
		break;
}

// Hide "Phone" and "fax" column
// echo date('H:i:s') , " Hide 'Phone' and 'fax' columns" , EOL;
// $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setVisible(false);
// $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setVisible(false);

// Set outline levels
// echo date('H:i:s') , " Set outline levels" , EOL;
// $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setOutlineLevel(1)
// ->setVisible(false)
// ->setCollapsed(true);

// Freeze panes
echo date ( 'H:i:s' ), " 엑셀 데이터의 첫 행을 인덱스로 고정합니다.", EOL;
$objPHPExcel->getActiveSheet ()->freezePane ( 'A2' );

// Rows to repeat at top
// echo date('H:i:s') , " Rows to repeat at top" , EOL;
$objPHPExcel->getActiveSheet ()->getPageSetup ()->setRowsToRepeatAtTopByStartAndEnd ( 1, 1 );

// Add data
require_once './class/DB2Excel.inc';

$DB2Excel = new DB2Excel ();
$DB2Excel->printExcel ( $objPHPExcel, $type, $sDate, $eDate );

// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex ( 0 );

// Save Excel 95 file
echo date ( 'H:i:s' ), " 데이터를 쓰는 중 입니다.", EOL;
$callStartTime = microtime ( true );

$objWriter = PHPExcel_IOFactory::createWriter ( $objPHPExcel, 'Excel5' );
$fileName = str_replace ( '.php', '', __FILE__ );

switch ($type){
	case 1:
		$fileName = $fileName . '_인력_' . date ( 'H-i-s' ) . '.xls';
		break;
	case 2:
		$fileName = $fileName . '_차량_' . date ( 'H-i-s' ) . '.xls';
		break;
	case 3:
		$fileName = $fileName . '_일결_' . date ( 'H-i-s' ) . '.xls';
		break;
	case 4:
		$fileName = $fileName . '_월결_' . date ( 'H-i-s' ) . '.xls';
		break;
}

$objWriter->save ( $fileName );
$callEndTime = microtime ( true );
$callTime = $callEndTime - $callStartTime;
$sFile = explode ( "/", $fileName );

echo date ( 'H:i:s' ), " 파일로 저장합니다. : ", $sFile [5], EOL;
echo date ( 'H:i:s' ), ' 총 쓰기 시간 ', sprintf ( '%.4f', $callTime ), " seconds", EOL;
// Echo memory usage
// echo date('H:i:s') , ' 현재까지 사용 메모리: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;

// Echo memory peak usage
// echo date('H:i:s') , " 사용된 메모리: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;

// Echo done
echo date ( 'H:i:s' ), " 파일 쓰기를 완료했습니다.", EOL;
echo date ( 'H:i:s' ), ' 파일이 생성되었습니다. ', EOL;

echo "<a href='./" . $sFile [5] . "'>Download File :" . $sFile [5] . "</a>";
?>
</div>
		</div>
	</div>
	<!-- /container -->

	<!-- Bootstrap core JavaScript
    ================================================== -->
	<!-- Placed at the end of the document so the pages load faster -->
	<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
	<script src="./dist/js/bootstrap.min.js"></script>
</body>
</html>